package com.iplatform.iplatformuser.privilege.api;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.swaggerbootstrapui.util.CommonUtils;
import com.iplatform.commons.pagination.Pagination;
import com.iplatform.commons.utils.CommResponse;
import com.iplatform.commons.utils.UserUtil;
import com.iplatform.iplatformuser.framework.springmvc.BaseController;
import com.iplatform.iplatformuser.privilege.service.inter.IPriMenuService;
import com.iplatform.iplatformuser.privilege.service.inter.IPriOptService;
import com.iplatform.module.privilege.PriManagerBean;
import com.iplatform.module.privilege.PriMenuBean;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.math.BigDecimal;
import java.util.*;


/**
 * 网站地图菜单管理接口
 *
 * @author ld
 */
@RestController
@RequestMapping("/api/v1/menu")
@Api(tags = "网站地图菜单管理接口")
public class ApiPriMenuController extends BaseController {
	
	@Autowired
	public IPriMenuService priMenuService;
	
	@Autowired
	public IPriOptService priOptService;
	
	@Value("${spring.datasource.driver-class-name}")
	private String dataSource;
	
	/**
	 * 菜单列表
	 *
	 * @param formMap
	 * @param pagination
	 * @return
	 */
	@ApiOperation(value = "菜单列表")
	@ApiImplicitParams({
			@ApiImplicitParam(dataType = "String", name = "menuName", value = "模糊查询菜单名称", required = false, paramType = "query")})
	@ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
			@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
	@GetMapping(value = "list")
	public ResponseEntity<PageInfo<PriMenuBean>> list(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap,
													  @ModelAttribute(value = "pagination") Pagination pagination) {
		
		
		if ("com.mysql.jdbc.Driver".equals(dataSource)) {
			List<PriMenuBean> resultList = new ArrayList<>();
			List<PriMenuBean> bean = priMenuService.queryMenuListByLevel(formMap);
			for (PriMenuBean test : bean) {
				PriMenuBean tmp = new PriMenuBean();
				try {
					tmp = (PriMenuBean) test.clone();
				} catch (CloneNotSupportedException e) {
					e.printStackTrace();
				}
				tmp.setChilds(null);
				tmp.setMenuName(space(tmp.getMenuName(), tmp.getMenuLevel()));
				resultList.add(tmp);
//				getChildList(resultList, test);
			}
			if (formMap.get("menuName") != null && formMap.get("menuName") != "") {
				List<PriMenuBean> list = new ArrayList<>();
				for (int i = 0; i < resultList.size(); i++) {
					if (resultList.get(i).getMenuName().contains(formMap.get("menuName"))) {
						list.add(resultList.get(i));
					}
				}
				resultList.clear();
				resultList = list;
			}
			initTree(resultList);
			PageInfo<PriMenuBean> pageInfo = new PageInfo<>();
			pageInfo.setTotal(resultList.size());
			pageInfo.setPages(resultList.size() / pagination.getPageSize() + 1);
			pageInfo.setPageNum(pagination.getPageNum());
			pageInfo.setPageSize(pagination.getPageSize());
			List<PriMenuBean> list = resultList.subList((pagination.getPageNum() - 1) * pagination.getPageSize(),
					(pagination.getPageNum() - 1) * pagination.getPageSize() + pagination.getPageSize() < resultList.size() ?
							(pagination.getPageNum() - 1) * pagination.getPageSize() + pagination.getPageSize() : resultList.size());
			pageInfo.setList(list);
			return new ResponseEntity<>(pageInfo, HttpStatus.OK);
		} else {
			PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize());
			List<PriMenuBean> resultList = priMenuService.queryMenuListByLevel(formMap);
			initTree(resultList);
			PageInfo<PriMenuBean> pageInfo = new PageInfo<PriMenuBean>(resultList);
			return new ResponseEntity<>(pageInfo, HttpStatus.OK);
		}
	}
	
	private void initTree(List<PriMenuBean> resultList) {
		for (int i = 0; i < resultList.size(); i++) {
			PriMenuBean currentMenuBean = resultList.get(i);
			
			if ("0".equals(currentMenuBean.getParentId())) {
				currentMenuBean.setTreeParentsId("0");
				currentMenuBean.setTreeId(String.valueOf(currentMenuBean.getMenuOrd()).trim());
			} else {
				currentMenuBean.setTreeParentsId(currentMenuBean.getAllParentsId().trim());
				currentMenuBean.setTreeId((currentMenuBean.getAllParentsId() + "-" + currentMenuBean.getMenuOrd()).trim());
			}
			
		}
	}
	
	private String space(String name, int level) {
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i < level; i++) {
			sb.append("        ");
		}
		return sb.toString() + name;
	}

//	public void getChildList(List<PriMenuBean> testList, PriMenuBean PriMenuBean) {
//		List<PriMenuBean> child = PriMenuBean.getChilds();
//		for(PriMenuBean chilTest : child) {
//			PriMenuBean tmp=new PriMenuBean();
//			try {
//				tmp=(PriMenuBean) chilTest.clone();
//			} catch (CloneNotSupportedException e) {
//				e.printStackTrace();
//			}
//			tmp.setChilds(null);
//			tmp.setMenuName(space(tmp.getMenuName(),tmp.getMenuLevel()));
//			testList.add(tmp);
//			getChildList(testList, chilTest);
//		}
//	}
	
	
	/**
	 * 分层菜单列表
	 *
	 * @param formMap
	 * @param pagination
	 * @return
	 */
	@ApiOperation(value = "分层菜单列表")
	@ApiImplicitParams({
			@ApiImplicitParam(dataType = "String", name = "menuName", value = "模糊查询菜单名称", required = false, paramType = "query")})
	@ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
			@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
	@GetMapping(value = "layer")
	public ResponseEntity<PageInfo<PriMenuBean>> layer(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap,
													   @ModelAttribute(value = "pagination") Pagination pagination) {
		
		PageHelper.startPage(pagination.getPageNum(), pagination.getPageSize());
		List<PriMenuBean> resultList = priMenuService.queryMenuListByLayer(formMap);
		PageInfo<PriMenuBean> pageInfo = new PageInfo<PriMenuBean>(resultList);
		
		return new ResponseEntity<>(pageInfo, HttpStatus.OK);
	}
	
	/**
	 * 菜单详情
	 *
	 * @param formMap
	 * @return
	 */
	@ApiOperation(value = "菜单详情", notes = "父id为0")
	@ApiImplicitParams({
			@ApiImplicitParam(dataType = "String", name = "menuId", value = "菜单ID", required = true, paramType = "query")})
	@ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
			@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
	@GetMapping(value = "detail")
	public ResponseEntity<PriMenuBean> detail(HttpServletRequest request,
											  @RequestParam @ApiParam(hidden = true) Map<String, String> formMap) {
		List<PriMenuBean> resultList = priMenuService.queryMenuListByLevel(formMap);
		PriMenuBean primenubean = null;
		if (resultList != null && resultList.size() > 0) {
			primenubean = resultList.get(0);
		} else {
			primenubean = null;
		}
		return new ResponseEntity<>(primenubean, HttpStatus.OK);
	}
	
	/**
	 * 新增菜单
	 *
	 * @param priMenuBean
	 * @return
	 */
	@ApiOperation(value = "新增菜单")
	@ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
			@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
	@PostMapping()
	public ResponseEntity<CommResponse> add(@RequestBody PriMenuBean priMenuBean) {
		
		if (StringUtils.isEmpty(priMenuBean.getMenuName())) {
			return new ResponseEntity<>(new CommResponse("菜单名称不能为空", false), HttpStatus.BAD_REQUEST);
		}
		if (priMenuBean.getMenuOrd() == null) {
			return new ResponseEntity<>(new CommResponse("菜单排序码不能为空", false), HttpStatus.BAD_REQUEST);
		}
		
		PriManagerBean pri = UserUtil.getLoginAppUser();
		if (StringUtils.isEmpty(priMenuBean.getParentId())) {
			priMenuBean.setMenuLevel(1);
			priMenuBean.setParentId("0");
		} else {
			Map<String, String> formMap = new HashMap<String, String>(16);
			formMap.put("MENU_ID", priMenuBean.getParentId());
			List<PriMenuBean> parentList = priMenuService.queryMenu(formMap);
			if (parentList != null && parentList.size() > 0) {
				priMenuBean.setMenuLevel(((PriMenuBean) parentList.get(0)).getMenuLevel() + 1);
			} else {
				priMenuBean.setMenuLevel(1);
			}
		}
		
		if (pri != null) {
			priMenuBean.setCreatedBy(pri.getUserCode());
		} else {
			priMenuBean.setCreatedBy("admin");
		}
		if (StringUtils.isEmpty(priMenuBean.getMenuCode())) {
			priMenuBean.setMenuCode(UUID.randomUUID().toString());
		}
		if (StringUtils.isEmpty(priMenuBean.getStatus())) {
			priMenuBean.setStatus("1");
		}
		if (StringUtils.isEmpty(priMenuBean.getIsDeleted())) {
			priMenuBean.setIsDeleted("N");
		}
		if (StringUtils.isEmpty(priMenuBean.getParentId())) {
			priMenuBean.setIsLeaf(BigDecimal.valueOf(0));
		} else {
			priMenuBean.setIsLeaf(BigDecimal.valueOf(1));
		}
		if (StringUtils.isEmpty(priMenuBean.getOpenMode())) {
			priMenuBean.setOpenMode("0");
		}
		priMenuService.insertMenu(priMenuBean);
		return new ResponseEntity<>(new CommResponse("添加成功", true), HttpStatus.CREATED);
	}
	
	/**
	 * 更新菜单
	 *
	 * @param priMenuBean
	 * @return
	 */
	@ApiOperation(value = "更新菜单")
	@ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
			@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
	@PutMapping()
	public ResponseEntity<CommResponse> update(@RequestBody PriMenuBean priMenuBean) {
		
		if (StringUtils.isEmpty(priMenuBean.getMenuName())) {
			return new ResponseEntity<>(new CommResponse("菜单名称不能为空", false), HttpStatus.BAD_REQUEST);
		}
		if (priMenuBean.getMenuOrd() == null) {
			return new ResponseEntity<>(new CommResponse("菜单排序码不能为空", false), HttpStatus.BAD_REQUEST);
		}
		
		PriManagerBean pri = UserUtil.getLoginAppUser();
		if (StringUtils.isEmpty(priMenuBean.getParentId())) {
			priMenuBean.setMenuLevel(1);
			priMenuBean.setParentId("0");
		} else {
			Map<String, String> formMap = new HashMap<String, String>(16);
			formMap.put("MENU_ID", priMenuBean.getParentId());
			List<PriMenuBean> parentList = priMenuService.queryMenu(formMap);
			if (parentList != null && parentList.size() > 0) {
				priMenuBean.setMenuLevel(((PriMenuBean) parentList.get(0)).getMenuLevel() + 1);
			} else {
				priMenuBean.setMenuLevel(1);
			}
		}
		if (pri != null) {
			priMenuBean.setUpdatedBy(pri.getUserCode());
		} else {
			priMenuBean.setUpdatedBy("admin");
		}
		
		priMenuService.updateMenu(priMenuBean);
		return new ResponseEntity<>(new CommResponse("更新成功", true), HttpStatus.OK);
		
	}
	
	/**
	 * 删除菜单
	 *
	 * @param deleteIds
	 * @return
	 */
	@ApiOperation(value = "删除菜单和相应的所有子菜单")
	@ApiImplicitParams({
			@ApiImplicitParam(dataType = "String", name = "deleteIds", value = "要删除的ID集合，逗号分隔", required = true, paramType = "query")
	})
	@ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
			@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
	@DeleteMapping()
	public ResponseEntity<CommResponse> del(@RequestParam String deleteIds) {
		
		priMenuService.batchDelete(deleteIds.split(","));
		
		return new ResponseEntity<>(new CommResponse("删除成功", true), HttpStatus.NO_CONTENT);
	}
	
	
	/**
	 * 获取未和菜单绑定的角色列表
	 *
	 * @param formMap
	 * @return
	 */
	@ApiOperation(value = "获取未和菜单绑定的角色列表")
	@ApiImplicitParams({
			@ApiImplicitParam(dataType = "String", name = "menuId", value = "菜单ID", required = true, paramType = "query"),
			@ApiImplicitParam(dataType = "String", name = "roleName", value = "菜单名称", required = false, paramType = "query"),
	})
	@ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
			@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
	@GetMapping(value = "/outRole")
	public ResponseEntity<List<Map<String, String>>> getOutRole(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {
		
		List<Map<String, String>> roleList = priMenuService.listSelectWithOutRole(formMap);
		
		return new ResponseEntity<>(roleList, HttpStatus.OK);
	}
	
	/**
	 * 获取已和菜单绑定的角色列表
	 *
	 * @param formMap
	 * @return
	 */
	@ApiOperation(value = "获取已和菜单绑定的角色列表")
	@ApiImplicitParams({
			@ApiImplicitParam(dataType = "String", name = "menuId", value = "菜单ID", required = true, paramType = "query"),
	})
	@ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
			@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
	@GetMapping(value = "/inRole")
	public ResponseEntity<List<Map<String, String>>> getInRole(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {
		
		List<Map<String, String>> roleList = priMenuService.listSelectWithInRole(formMap);
		
		return new ResponseEntity<>(roleList, HttpStatus.OK);
	}
	
	/**
	 * 绑定角色
	 *
	 * @param menuId
	 * @param checkedIds
	 * @return
	 */
	@ApiOperation(value = "绑定角色")
	@ApiImplicitParams({
			@ApiImplicitParam(dataType = "String", name = "menuId", value = "菜单ID", required = true, paramType = "query"),
			@ApiImplicitParam(dataType = "String", name = "checkedIds", value = "角色ID集合，逗号分隔", required = true, paramType = "query"),
	})
	@ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
			@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
	@PutMapping(value = "/bindRole")
	public ResponseEntity<CommResponse> bindRole(@RequestParam String menuId, @RequestParam String checkedIds) {
		priMenuService.updateHomeRole(menuId, checkedIds);
		
		return new ResponseEntity<>(new CommResponse("绑定角色成功", true), HttpStatus.OK);
	}
	
	/**
	 * 地图新增和编辑页面上级地图下拉框
	 *
	 * @param formMap
	 * @return
	 */
	@ApiOperation(value = "地图新增和编辑页面上级地图下拉框")
	@ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
			@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
	@GetMapping(value = "/maps")
	public ResponseEntity<List<PriMenuBean>> selectedMaps(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {
		
		List<PriMenuBean> menuList = priMenuService.queryMenuListByLevel(formMap);
		
		return new ResponseEntity<>(menuList, HttpStatus.OK);
	}
	
	
	@ApiOperation(value = "查询父子节点")
	@ApiImplicitParams({
			@ApiImplicitParam(dataType = "String", paramType = "query", name = "menuName", value = "菜单名称", required = true)
	})
	@ResponseBody
	@GetMapping(value = "nodeByName")
	public ResponseEntity<List<PriMenuBean>> querySelectedByName(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {
		List<PriMenuBean> menuList = priMenuService.querySelectedByName(formMap);
		return new ResponseEntity<>(menuList, HttpStatus.OK);
	}
	
	
	/**
	 * 绑定功能回显
	 *
	 * @param menuId
	 * @return
	 */
	@ApiOperation(value = "绑定功能回显*")
	@ApiImplicitParams({
			@ApiImplicitParam(dataType = "String", name = "menuId", value = "菜单ID",
					required = true, paramType = "query")
	})
	@ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
			@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
	@GetMapping(value = "/bindFunction")
	public ResponseEntity<List<Map<String, String>>> selectedBindFunction(@RequestParam String menuId) {
		
		List<Map<String, String>> resultList = priMenuService.querySelectOptByMenuId(menuId);
		
		return new ResponseEntity<>(resultList, HttpStatus.OK);
	}
	
	/**
	 * 绑定功能保存
	 *
	 * @param menuId
	 * @param checkedIds
	 * @return
	 */
	@ApiOperation(value = "绑定功能保存*", notes = "涉及到stbl_pri_menu_opt,STBL_PRI_RESOURCES_OPT")
	@ApiImplicitParams({
			@ApiImplicitParam(dataType = "String", name = "menuId", value = "菜单ID", required = true, paramType = "query"),
			@ApiImplicitParam(dataType = "String", name = "checkedIds", value = "绑定的ID集合", required = false, paramType = "query")
	})
	@ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
			@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
	@PutMapping(value = "/bindFunction")
	public ResponseEntity<CommResponse> updateBindFunction(String menuId, String[] checkedIds) {
		
		PriManagerBean priManager = UserUtil.getLoginAppUser();
		
		priMenuService.menuSelectedOpt(menuId, checkedIds, "admin");
		
		return new ResponseEntity<>(new CommResponse("绑定操作成功", true), HttpStatus.OK);
	}
	
	/**
	 * 菜单列表，不分页，树状
	 *
	 * @param formMap
	 * @return
	 * @throws Exception
	 */
	@ApiOperation(value = "菜单列表，不分页，树状")
	@GetMapping(value = "listForTree")
	public ResponseEntity<JSONObject> listForTree(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) throws Exception {
		JSONObject json = new JSONObject();
		List<Map<String, String>> listForTree = priMenuService.listForTree(formMap);
		json.put("code", 200);
		json.put("msg", "");
		json.put("status", 0);
		json.put("count", listForTree.size());
		json.put("data", listForTree);
		return new ResponseEntity<>(json, HttpStatus.OK);
	}
	
	/**
	 * 查询地图名称
	 *
	 * @return
	 */
	@ApiOperation(value = "查询地图名称")
	@GetMapping(value = "/menuNameList")
	public ResponseEntity<JSONObject> queryMenuNameList() {
		
		List<Map<String, String>> resultList = priMenuService.queryMenuName();
		
		JSONObject allObject = new JSONObject();
		JSONArray arrayName = new JSONArray();
		
		for (Map<String, String> nameList : resultList) {
			JSONObject objectName = new JSONObject();
			objectName.put("menuName", nameList.get("menuName"));
			arrayName.add(objectName);
		}
		allObject.put("name", arrayName);
		return new ResponseEntity<>(allObject, HttpStatus.OK);
	}
	
	
	/**
	 * 登陆时查询用户详情
	 *
	 * @return
	 */
	@ApiOperation(value = "通过图册id查询菜单id")
	@ApiImplicitParams({
			@ApiImplicitParam(dataType = "String", name = "bookIds", value = "多个连接，逗号分隔", required = true)})
	@ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
			@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
	@GetMapping(value = "/book")
	public List<String> queryMenuByBookId(@RequestParam String bookIds) {
		return priMenuService.queryMenuByBookId(Arrays.asList(bookIds.split(",")));
	}
	
	/**
	 * 获取所有菜单
	 *
	 * @param formMap
	 * @return
	 */
	@ApiOperation(value = "获取所有菜单")
	@ApiImplicitParams({
			@ApiImplicitParam(dataType = "String", name = "menuName", value = "模糊查询菜单名称", required = false, paramType = "query"),
			@ApiImplicitParam(dataType = "String", name = "status", value = "菜单状态", required = false, paramType = "query"),
			@ApiImplicitParam(dataType = "String", name = "systemCode", value = "是哪个系统的菜单", required = false, paramType = "query"),
			@ApiImplicitParam(dataType = "String", name = "menuType", value = "菜单类型，0为系统，1为功能", required = false, paramType = "query"),
			@ApiImplicitParam(dataType = "String", name = "openMode", value = "菜单打开方式,0为内部打开,1为新窗口打开", required = false, paramType = "query")
	})
	@ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
			@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
	@GetMapping(value = "listAll")
	public ResponseEntity<List<PriMenuBean>> listAll(@ApiParam(hidden = true) @RequestParam Map<String, String> formMap) {
		if (StringUtils.isEmpty(formMap.get("menuName"))) {
			formMap.put("parentId", "0");
		}
		List<PriMenuBean> menuBeanList = priMenuService.queryMenuByParentId(formMap);
		return new ResponseEntity<>(menuBeanList, HttpStatus.OK);
	}
	
	@ApiOperation(value = "更改菜单状态")
	@ApiImplicitParams({
			@ApiImplicitParam(dataType = "String", name = "menuId", value = "菜单id", required = true),
			@ApiImplicitParam(dataType = "String", name = "status", value = "菜单状态", required = true)})
	@PutMapping(value = "status")
	public ResponseEntity<CommResponse> updateStatus(@RequestParam String menuId, String status) {
		priMenuService.updateStatus(status, menuId);
		return new ResponseEntity<>(new CommResponse("更改菜单状态成功.", true), HttpStatus.OK);
	}
	
	@ApiOperation(value = "根据数据字典类型code获取菜单id")
	@GetMapping(value = "findMenuIdBySysDataCodeType")
	@ApiResponses({@ApiResponse(code = HttpServletResponse.SC_OK, message = "成功"),
			@ApiResponse(code = HttpServletResponse.SC_CONFLICT, message = "没有做到API使用规范")})
	public ResponseEntity<PriMenuBean> findMenuIdBySysDataCodeType(@RequestParam String typeCode) {
		PriMenuBean priMenuBean = priMenuService.findMenuIdBySysDataCodeType(typeCode);
		return new ResponseEntity(priMenuBean, HttpStatus.OK);
	}
	
	/**
	 * 删除菜单
	 *
	 * @param menuId
	 * @return
	 */
	@ApiOperation(value = "删除菜单")
	@ApiImplicitParams({
			@ApiImplicitParam(dataType = "String", name = "menuId", value = "菜单id", required = true)
	})
	@PutMapping("/remove")
	public ResponseEntity<CommResponse> deleteMenu(@RequestParam String menuId) {
		Integer childNum = priMenuService.queryChildMenuNum(menuId);
		if (childNum > 0) {
			return new ResponseEntity<>(new CommResponse("当前菜单下有子菜单,暂时不可删除", false), HttpStatus.BAD_REQUEST);
		}
		priMenuService.delMenu(menuId);
		return new ResponseEntity<>(new CommResponse("删除成功", true), HttpStatus.NO_CONTENT);
	}

	/**
	 * 查询同级最大排序码
	 *
	 * @param parent_id
	 * @return
	 */
	@ApiOperation(value = "查询同级最大排序码")
	@ApiImplicitParams({
			@ApiImplicitParam(dataType = "String", name = "parent_id", value = "父级ID", required = true)
	})
	@GetMapping("/queryMaxOrd")
	public ResponseEntity<Integer> queryMaxOrd(@RequestParam String parent_id) {
		Integer maxOrd = priMenuService.queryMaxOrd(parent_id);
		return new ResponseEntity<>(maxOrd, HttpStatus.OK);
	}

	
}
